<?php
/**
 * Created by PhpStorm.
 * User: steven
 * Date: 2017/11/12
 * Time: 下午9:50
 */

namespace app\api\validate;


use app\lib\exception\ParameterException;
use think\Exception;
use think\Request;
use think\Validate;

class BaseValidate extends Validate {

    public function goCheck(){
        // 获取http传入的参数
        // 对这些参数进行校验

        $requests = Request::instance();
        $params   = $requests->param();
        $result   = $this->check($params);

        if(!$result){
            $e = new ParameterException([
                'msg' => $this->error,
            ]);
            throw $e;
//            $error = $this->getError();
//            throw new Exception($error);
        }else{
            return true;
        }
    }

    protected function isPositiveInteger($value,$rule = '',$data = '',$field = ''){

        if (is_numeric($value) && is_int($value + 0) && ($value +0) > 0){

            return true;
        }
        else{
//            return $field.'必须是正整数';
            return false;
        }
    }

    protected function isNotEmpty($value,$rule='',$data = '',$field = ''){

        if(empty($value)){

            return false;

        }else{
            return true;
        }
    }
}